Skip to content

Conversation

@MarcusGoldschmidt
Copy link
Contributor

@MarcusGoldschmidt MarcusGoldschmidt commented May 22, 2025

Fix sync all databases when not using postgres default user

  • Fix sync all databases when not using postgres superuser
  • Add a new flag to enable sync all databases

Summary by CodeRabbit

  • New Features

    • Added a configuration option to enable synchronization of all databases for PostgreSQL connections.
  • Bug Fixes

    • Improved handling of default database selection when listing databases.
  • Documentation

    • Updated configuration schema with a new field description for syncing all databases.

@coderabbitai
Copy link

coderabbitai bot commented May 22, 2025

Walkthrough

A new boolean configuration option, syncAllDatabases, has been introduced to control whether all PostgreSQL databases should be synchronized or just the default one. This change propagates through configuration, connector, and database syncer logic, and updates client pool handling to support the new flag.

Changes

File(s) Change Summary
pkg/config/conf.gen.go, pkg/config/config.go Added syncAllDatabases boolean field to PostgreSQL config structs and schema.
pkg/connector/connector.go Added syncAllDatabases field to the Postgresql struct and updated constructors/methods to accept and use this flag.
pkg/connector/database.go Added syncAllDatabases to databaseSyncer, updated logic in List to filter databases based on the flag, and updated constructor.
pkg/postgres/client.go Removed DefaultDatabase logic and special handling for default database; added DatabaseName() method to Client.

Sequence Diagram(s)

sequenceDiagram
    participant Config
    participant Connector
    participant DatabaseSyncer
    participant ClientPool
    participant Client

    Config->>Connector: Pass syncAllDatabases flag
    Connector->>DatabaseSyncer: Initialize with syncAllDatabases
    DatabaseSyncer->>ClientPool: Request list of databases
    alt syncAllDatabases == true
        DatabaseSyncer->>ClientPool: Get all databases
    else syncAllDatabases == false
        DatabaseSyncer->>ClientPool: Get default Client
        ClientPool->>Client: Return default Client
        Client->>DatabaseSyncer: Return default DatabaseName
    end
    DatabaseSyncer->>Connector: Return filtered database list
Loading

Possibly related PRs

  • Multiple database support #31: Implements multi-database support by replacing single database clients with a client pool and updating syncers for multi-database handling, which is foundational for the new syncAllDatabases flag logic.

Suggested reviewers

  • laurenleach

Poem

In the warren of code, a new flag appears,
To sync all databases, or just one, it steers.
With a hop and a skip, the logic refined—
Now choose your own sync, and leave none behind!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

level=warning msg="[runner] Can't run linter goanalysis_metalinter: buildir: failed to load package : could not load export data: no export data for "github.com/conductorone/baton-sdk/pkg/field""
level=error msg="Running error: can't run linter goanalysis_metalinter\nbuildir: failed to load package : could not load export data: no export data for "github.com/conductorone/baton-sdk/pkg/field""

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 33c1069 and f84b627.

⛔ Files ignored due to path filters (2)
  • README.md is excluded by none and included by none
  • cmd/baton-postgresql/main.go is excluded by none and included by none
📒 Files selected for processing (5)
  • pkg/config/conf.gen.go (1 hunks)
  • pkg/config/config.go (1 hunks)
  • pkg/connector/connector.go (4 hunks)
  • pkg/connector/database.go (3 hunks)
  • pkg/postgres/client.go (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
pkg/connector/database.go (1)
pkg/postgres/client.go (2)
  • ClientDatabasesPool (12-19)
  • Client (96-100)
pkg/postgres/client.go (2)
pkg/postgres/logger.go (1)
  • Logger (12-12)
pkg/connector/connector.go (1)
  • New (64-77)
pkg/connector/connector.go (2)
pkg/postgres/client.go (1)
  • New (119-146)
pkg/config/conf.gen.go (1)
  • Postgresql (6-12)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: go-lint
  • GitHub Check: test
🔇 Additional comments (15)
pkg/config/conf.gen.go (1)

11-11: Looks good: New configuration field properly added

The SyncAllDatabases boolean field is correctly added to the Postgresql struct with the appropriate mapstructure tag. This will allow the configuration system to properly map this option from configuration files or environment variables.

pkg/config/config.go (2)

12-12: Well-defined configuration field with helpful description

The new syncAllDatabases field is correctly defined with an appropriate description that clearly communicates its purpose and potential impact ("This can result in large amounts of data"). The default value of false is a good conservative choice that maintains backward compatibility.


19-19: Config schema updated correctly

The syncAllDatabases field has been properly added to the configuration schema, ensuring it will be recognized by the configuration system.

pkg/connector/connector.go (4)

19-19: LGTM: Connector struct updated with new flag

The syncAllDatabases boolean field has been correctly added to the Postgresql struct.


32-32: LGTM: Flag properly passed to database syncer

The new flag is correctly passed to the newDatabaseSyncer constructor, ensuring the database syncer will have the information it needs to determine which databases to sync.


64-64: Constructor signature properly updated

The New constructor function has been correctly updated to accept the new syncAllDatabases parameter.


75-75: Field initialization looks good

The syncAllDatabases field is properly initialized in the constructor.

pkg/connector/database.go (4)

26-30: Struct fields properly organized

The databaseSyncer struct has been updated with a cleaner field organization and the new syncAllDatabases boolean field.


68-68: Default client reference improved

The code now properly stores the default database client in a local variable for better readability and to avoid multiple calls to Default(ctx).


72-72: Key feature implementation: Conditional database filtering

This is the core of the feature - databases are now conditionally filtered based on the syncAllDatabases flag. If the flag is false, only the default database is included; otherwise, all databases are processed. This implementation directly addresses the PR objective of enabling synchronization of all databases when desired.


333-339: Constructor properly updated

The newDatabaseSyncer constructor has been correctly updated to accept the syncAllDatabases parameter and initialize all the fields.

pkg/postgres/client.go (4)

12-19: Code structure simplification looks good

The ClientDatabasesPool struct now has a cleaner structure without the separate default client with database field, aligning with the PR's objective to support synchronizing all databases.


30-37: Initialization structure properly matches struct definition

The constructor initialization correctly matches the updated struct definition and properly initializes all fields with appropriate values.


44-94: Get method logic improved

The method now consistently uses the default client DSN to fetch database metadata, regardless of the database name provided, removing the special case handling for empty database names. This approach is more consistent and better supports the multi-database synchronization feature.


148-150: Good addition of DatabaseName() accessor

This accessor method enhances the API by providing a clean way to retrieve the database name from the client's configuration. It supports the PR's goal of enabling synchronization of all databases by making the database name easily accessible.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@MarcusGoldschmidt MarcusGoldschmidt changed the title fix: sync all databases #BB-754 fix: sync all databases May 22, 2025
@MarcusGoldschmidt MarcusGoldschmidt merged commit 1c13c0c into main May 22, 2025
4 checks passed
@MarcusGoldschmidt MarcusGoldschmidt deleted the goldschmidt/fix-sync-all-databases branch May 22, 2025 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants